package main

import (
	"fmt"
	"os"
)

func add(a, b int) int {
	return a + b
}
func mi(a, b int) int {
	return a - b
}

type fu func(int, int) int //函数类型

func test(a, b int, f fu) int { //回调函数 函数参数是函数类型
	return f(a, b)
}

type student struct {
	person
	age  int
	name string
	int
}
type person struct {
	tel int
}

//为student 添加方法
func (tmp *student) init(age int, name string, a int, tel int) {
	tmp.age = age
	tmp.name = name
	tmp.int = a
	tmp.tel = tel
}
func main() {
	fmt.Println("hellow owrld")
	a := test(1, 2, mi) //多态
	fmt.Println(a)      //延迟调用
	//匿名函数
	func() {
		//无参 可以直接使用外界参数，引用捕获默认
		a += 1
	}()
	fmt.Println(a)
	lists := os.Args //命令行参数 字符串数组
	fmt.Println(len(lists))
	arr := []int{1, 2, 3}
	arr = append(arr, 4)
	for i, data := range arr {
		fmt.Println(i, " ", data)
	}
	//map
	m1 := map[int]string{1: "a"} //初始化自动推导会给空间而栈上定义没空间
	m1[2] = "b"
	fmt.Println(len(m1), " ", m1)
	value, flag := m1[3]
	if flag == true {
		fmt.Println("存在", value)
	} else {
		fmt.Println("不存在")
	}
	delete(m1, 1)
	fmt.Println(len(m1), " ", m1) //map做参数引用传递
	s1 := student{person{123}, 1, "2", 1}
	s1.tel = 1234
	s1.int = 222
	fmt.Println(s1)
	var s2 *student = new(student)
	s2.age = 1
	fmt.Println(s2)

	var st *student = new(student)
	st.init(1, "1", 1, 1)
	fmt.Println(st)
	//匿名字段用于继承
}
